﻿using System.Linq;

namespace TIKSN.StringSearchingAlgorithms.Tests
{
    internal static class Helper
    {
        public static System.Collections.Generic.IEnumerable<StringSearchingAlgorithms.ITextComparer> GetAllTextComparers()
        {
            var algorithms = new System.Collections.Generic.List<StringSearchingAlgorithms.ITextComparer>();

            algorithms.Add(new StringSearchingAlgorithms.LongestCommonSubsequence());

            return algorithms;
        }

        public static System.Collections.Generic.IEnumerable<string> GenerateRandomStrings()
        {
            const string SpaceSymbol = " ";
            const int SpaceFrequency = 5;
            const int MinimulStringLength = 1;
            const int MaximumStringLength = 20;
            const int StringsCount = 500;

            var alphabet = new System.Collections.Generic.HashSet<char>();
            var results = new System.Collections.Generic.List<string>();

            // Latin letters, symbols, numbers
            for (int i = 0x0021; i <= 0x007E; i++)
            {
                alphabet.Add((char)i);
            }

            for (int i = 0x00A1; i <= 0x00FF; i++)
            {
                alphabet.Add((char)i);
            }

            for (int i = 0x0100; i <= 0x017F; i++)
            {
                alphabet.Add((char)i);
            }

            for (int i = 0x0180; i <= 0x024F; i++)
            {
                alphabet.Add((char)i);
            }

            // Greek and Coptic letters and symbols

            for (int i = 0x0374; i <= 0x03FF; i++)
            {
                alphabet.Add((char)i);
            }

            // Cyrillic letters and symbols

            for (int i = 0x0400; i <= 0x04FF; i++)
            {
                alphabet.Add((char)i);
            }

            for (int i = 0x0500; i <= 0x0527; i++)
            {
                alphabet.Add((char)i);
            }

            // Armenian letters and symbols

            for (int i = 0x0531; i <= 0x0556; i++)
            {
                alphabet.Add((char)i);
            }

            for (int i = 0x0559; i <= 0x055F; i++)
            {
                alphabet.Add((char)i);
            }

            for (int i = 0x0561; i <= 0x0587; i++)
            {
                alphabet.Add((char)i);
            }

            for (int i = 0x0589; i <= 0x058A; i++)
            {
                alphabet.Add((char)i);
            }

            for (int i = 0x058F; i <= 0x058F; i++)
            {
                alphabet.Add((char)i);
            }

            // Generate strings
            var RNG = new System.Random();

            for (int i = 0; i < StringsCount; i++)
            {
                string GeneratedString = string.Empty;
                int length = RNG.Next(MinimulStringLength, MaximumStringLength);

                for (int j = 0; j < length; j++)
                {
                    if (RNG.Next(SpaceFrequency) == 0)
                    {
                        GeneratedString += SpaceSymbol;
                    }
                    else
                    {
                        int cindex = RNG.Next(alphabet.Count);
                        GeneratedString += alphabet.Skip(cindex).First();
                    }
                }

                results.Add(GeneratedString);
            }

            return results;
        }
    }
}
